package reflect;
/*
 * 反射调用私有方法
 * 通过反射获取私有方法，并设置访问权限为true

 */
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo7 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class c=Class.forName("reflect.Person");
        Object o = c.newInstance();
        Method method = c.getDeclaredMethod("hehe");
        method.setAccessible(true);//强制调用私有方法
        method.invoke(o);
        method.setAccessible(false);
    }
}
